﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Matchmaking>
@{
    this.ViewBag.Title = "Matchmaking";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var partners = this.ViewData["Partners"] as List<MatchmakingPartner> ?? new List<MatchmakingPartner>();
    var partnerTypes = this.ViewData["PartnerTypes"] as List<MatchmakingPartnerType> ?? new List<MatchmakingPartnerType>();
    var locations = this.ViewData["Locations"] as List<Location> ?? new List<Location>();
}

<div class="float-right smallMarginBottom">
    <input type="button" onclick="@string.Format("location.href = '{0}';", this.Url.Action("NewMatchmaking"))" value="Opret nyt" class="" />
</div>
<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (Matchmaking mm in this.Model.List)
        {
            List<Location> locs = locations.Where(x => x.ID == mm.Location).ToList();
            Location location = locs.Count() > 0 ? locations[0] : null;
        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", mm.Date)</td>
            <td>
                @if (location != null)
                {
                    @location.Name
                }
            </td>
            <td>@mm.Name</td>

            <td>
                @if (mm.Partners != null && mm.Partners.Count() > 0)
                {
                    Matchmaking mm1 = mm;
                    var mmPartners = partners.Where(x => mm1.Partners.Contains(x.ID)).Select(x => x.Type);
                    @Html.Raw(string.Join(", ", partnerTypes.Where(x => mmPartners.Contains(x.ID)).Select(x => x.Name)))
                }
            </td>

            <td>
                @mm.Comments
            </td>
            <td>
                <a href="@Url.Action("UpdateMAtchmaking", new { @Id = mm.ID })">
                <img src="@Url.Content("~/Content/ButtonIcons/tool_blue.png")" alt="Link"/></a>
            </td>
        </tr>
        }
    }
    <tr>
        @Html.Partial("~/Views/_Shared/PagingArrows.cshtml", new PagingArrows { Action = "Index", TotalAmountOfColumns = 6, CurrentSkip = this.Model.Skip, CurrentTake = this.Model.Take, CurrentTotalRowCount = this.Model.TotalRows })
    </tr>
</table>
